//
//  Preview_DocumentViewController.m
//  fxxiaoke
//
//  Created by 鞠超 on 2016/10/24.
//  Copyright © 2016年 jc. All rights reserved.
//

#import "Preview_DocumentViewController.h"

#import "Save_UserDunPanViewController.h"

@interface Preview_DocumentViewController ()

@property (nonatomic, strong) UIWebView * webView;

@property (nonatomic, strong) UIView * view_Bottom;

@end

@implementation Preview_DocumentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navi];
    
    [self p_bottomView];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void )p_navi
{
    _btnLeft.hidden = YES;
    _lblLeft.hidden = YES;
    _btnRight.hidden = YES;
    _lblRight.hidden = YES;
    
    _lblTitle.text = @"预览";
    _topView.backgroundColor = navi_bar_bg_color;
    
    //左返回
    UIImageView * image_LeftRetrun = [[UIImageView alloc] initWithFrame:CGRectMake(11, 31.5, 25, 25)];
    image_LeftRetrun.userInteractionEnabled = YES;
    image_LeftRetrun.image = [UIImage imageNamed:@"Left-return.png"];
    [_topView addSubview:image_LeftRetrun];
    
    UILabel * lbl_return = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_LeftRetrun.frame) - 6, 35, 75, 15)];
    lbl_return.text = @"公司文件";
    lbl_return.textColor = [UIColor whiteColor];
    lbl_return.font = [UIFont systemFontOfSize:17];
    [_topView addSubview:lbl_return];
    
    UIButton * btn_return = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_return.frame = CGRectMake(10, 22, 90, 40);
    [_topView addSubview:btn_return];
    [btn_return addTarget:self action:@selector(btn_returnAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

//左返回
- (void )btn_returnAction:(UIButton *)sender
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

//显示tabbar
- (void )viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

#pragma mark - 布局
- (void )p_setupView
{
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 50)];
    self.webView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    NSString * path = @"http://www.baidu.com";
    NSURL * url = [NSURL URLWithString:path];
    [self.webView loadRequest:[NSURLRequest requestWithURL:url]];
    
    [self.view addSubview:self.webView];
}

#pragma mark - 底部栏
- (void )p_bottomView
{
    self.view_Bottom = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 50, SCREEN_WIDTH, 50)];
    self.view_Bottom.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view addSubview:self.view_Bottom];
    
    CGFloat length_x = SCREEN_WIDTH / 3;
    
    //转发
    UIImageView * image_forward = [[UIImageView alloc] initWithFrame:CGRectMake(length_x / 4, 12.5, 25, 25)];
    image_forward.image = [UIImage imageNamed:@"Forwarding_black.png"];
    [self.view_Bottom addSubview:image_forward];
    
    UILabel * lbl_forward = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_forward.frame) + 3, 15, 40, 20)];
    lbl_forward.text = @"转发";
    lbl_forward.textColor = [UIColor grayColor];
    lbl_forward.font = [UIFont systemFontOfSize:15.0f];
    [self.view_Bottom addSubview:lbl_forward];
    
    UIButton * btn_forward = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn_forward.frame = CGRectMake(0, 0, length_x, 50);
    [self.view_Bottom addSubview:btn_forward];
    [btn_forward addTarget:self action:@selector(btn_forwardAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //存至网盘
    UIImageView * image_DunPan = [[UIImageView alloc] initWithFrame:CGRectMake(length_x + length_x / 5, 12.5, 25, 25)];
    image_DunPan.image = [UIImage imageNamed:@"DunPan_black.png"];
    [self.view_Bottom addSubview:image_DunPan];
    
    UILabel * lbl_DunPan = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_DunPan.frame) + 3, 15, 70, 20)];
    lbl_DunPan.text = @"存至网盘";
    lbl_DunPan.textColor = [UIColor grayColor];
    lbl_DunPan.font = [UIFont systemFontOfSize:15.0f];
    [self.view_Bottom addSubview:lbl_DunPan];
    
    UIButton * btn_DunPan = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn_DunPan.frame = CGRectMake(length_x, 0, length_x, 50);
    [self.view_Bottom addSubview:btn_DunPan];
    [btn_DunPan addTarget:self action:@selector(btn_DunPanAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //更多
    UIImageView * image_more = [[UIImageView alloc] initWithFrame:CGRectMake(length_x * 2 + length_x / 4, 12.5, 25, 25)];
    image_more.image = [UIImage imageNamed:@"more_black.png"];
    [self.view_Bottom addSubview:image_more];
    
    UILabel * lbl_more = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_more.frame) + 3, 15, 40, 20)];
    lbl_more.text = @"更多";
    lbl_more.textColor = [UIColor grayColor];
    lbl_more.font = [UIFont systemFontOfSize:15.0f];
    [self.view_Bottom addSubview:lbl_more];
    
    UIButton * btn_more = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn_more.frame = CGRectMake(length_x * 2, 0, length_x, 50);
    [self.view_Bottom addSubview:btn_more];
    [btn_more addTarget:self action:@selector(btn_moreAction:) forControlEvents:(UIControlEventTouchUpInside)];

}

#pragma mark - 点击转发
- (void )btn_forwardAction:(UIButton *)sender
{
//    NSLog(@"点击转发");
    
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:(UIAlertControllerStyleActionSheet)];
    [self presentViewController:alert animated:YES completion:^{
    }];
    
    UIAlertAction * action_Forwarding = [UIAlertAction actionWithTitle:@"转发到企信" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        
        NSLog(@"转发到企信");
    }];
    [alert addAction:action_Forwarding];
    
    UIAlertAction * action_Forwarding1 = [UIAlertAction actionWithTitle:@"转发到分享" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        
        NSLog(@"转发到分享");
    }];
    [alert addAction:action_Forwarding1];
    
    UIAlertAction * action_Cancel = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {
    }];
    [alert addAction:action_Cancel];
}

#pragma mark - 点击存至网盘
- (void )btn_DunPanAction:(UIButton *)sender
{
//    NSLog(@"点击存至网盘");
    
    Save_UserDunPanViewController * save_UserDunPanViewController = [[Save_UserDunPanViewController alloc] init];
    [self presentViewController:save_UserDunPanViewController animated:YES completion:^{
    }];
}

#pragma mark - 点击更多
- (void )btn_moreAction:(UIButton *)sender
{
//    NSLog(@"点击更多");
    
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:(UIAlertControllerStyleActionSheet)];
    [self presentViewController:alert animated:YES completion:^{
    }];
    
    UIAlertAction * action_Forwarding = [UIAlertAction actionWithTitle:@"用其他应用打开" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        
        NSLog(@"用其他应用打开");
    }];
    [alert addAction:action_Forwarding];
        
    UIAlertAction * action_Cancel = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {
    }];
    [alert addAction:action_Cancel];
}



@end
